package com.incar.chuxing.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.incar.chuxing.R;

/**
 * Created by jieyaozu on 2017/4/7.
 */

public class TextTextView extends LinearLayout {
    private TextView tvKey;
    private TextView tvValue;
    private int keySize;
    private int valueSize;
    private int keyColor;
    private int valueColor;
    private String keyText;
    private String valueText;

    public String getValueText() {
        return tvValue.getText().toString().trim();
    }

    public void setValueText(String text) {
        tvValue.setText(text);
    }

    public TextTextView(Context context) {
        super(context);
        initView(context);
    }

    public TextTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TextTextView);
        keySize = typedArray.getDimensionPixelSize(R.styleable.TextTextView_key_textsize, 14);
        valueSize = typedArray.getDimensionPixelSize(R.styleable.TextTextView_value_textsize, 14);
        keyColor = typedArray.getColor(R.styleable.TextTextView_key_textcolor, Color.GRAY);
        valueColor = typedArray.getColor(R.styleable.TextTextView_value_textcolor, Color.GRAY);
        keyText = typedArray.getString(R.styleable.TextTextView_key_text);
        valueText = typedArray.getString(R.styleable.TextTextView_value_text);
        tvKey.setTextSize(keySize);
        tvKey.setTextColor(keyColor);
        tvKey.setText(keyText);

        tvValue.setTextSize(valueSize);
        tvValue.setTextColor(valueColor);
        tvValue.setText(valueText);
        typedArray.recycle();
    }

    protected void initView(Context context) {
        View view = View.inflate(context, R.layout.widget_texttext_view, this);
        tvKey = (TextView) view.findViewById(R.id.widget_text_key);
        tvValue = (TextView) view.findViewById(R.id.widget_text_value);
    }
}
